<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class ads_class extends CI_Model {
	
		public function ads_list(){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->order_by("intID", "asc");
				$query = $this->db->get_where('jtn_adds',array('intDisabled'=>0,'intID'=>$intID));
			} else {
				$this->db->order_by("intID", "asc");
				$query = $this->db->get_where('jtn_adds',array('intDisabled'=>0));
			}
			if ($query->num_rows() > 0){
				$result = $query->result_array();
				return $result;
			}
			else{
				return 0;
			}
		}

		public function update($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$strAddName= stripslashes(filter_var($post['strAddName'], FILTER_SANITIZE_STRING));
			$intMSDelay= stripslashes(filter_var($post['intMSDelay'], FILTER_SANITIZE_STRING));
			$intOrder= stripslashes(filter_var($post['intOrder'], FILTER_SANITIZE_STRING));
			$intType= stripslashes(filter_var($post['intType'], FILTER_SANITIZE_STRING));
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
			$strNotes = $post['strNotes'];
		
			$data = array(
					'strAddName' => $strAddName,
					'strNotes' => $strNotes,
					'intType' => $intType,
					'intMSDelay' => $intMSDelay,
					'intOrder' => $intOrder,
					'strImgLink' => $strImgLink,
					'strModifiedBy'=> $this->session->userdata('intID'),
					'dateModifiedDate'=> date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_adds', $data);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function get_ads($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intID'=>$intID));
			} 
			$query = $this->db->get('jtn_adds')->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}

		public function get_ads_type($post){
			if(isset($post['intType'])){
				$intCode = stripslashes(filter_var($post['intType'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intCode'=>$intCode));
			}
			$query = $this->db->get('jtn_addtypes')->result_array();
			$query = current($query);
		
			if(trim($query['intCode'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function delete($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));	
		
			$data = array(
					'intDisabled' => 1,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
				
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_adds', $data);
				
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function insert($post){
			$adsType = stripslashes(filter_var($post['adsType'], FILTER_SANITIZE_STRING));
			$adsDelay = stripslashes(filter_var($post['adsDelay'], FILTER_SANITIZE_STRING));
			$adsName = stripslashes(filter_var($post['adsName'], FILTER_SANITIZE_STRING));
			$adsNote = stripslashes(filter_var($post['adsNote'], FILTER_SANITIZE_STRING));
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
				
			$data = array(
					'intType' => $adsType,
					'intMSDelay' => $adsDelay,
					'strAddName' => $adsName,
					'strNotes' => $adsNote,
					'strImgLink' => $strImgLink,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);

			$this->db->insert('jtn_adds', $data);
			
			$this->db->where(array('intID'=>$this->db->insert_id()));
			$this->db->update('jtn_adds', array('intOrder'=>$this->db->insert_id()));
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
	} // end class
?>